﻿using Md.Api.Model;
using Md.Api.Model.Manage.SysDept.Request;
using Md.Api.Service.Manage.SysDept;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Manage;
/// <summary>
/// 系统部门
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/manage/system/dept")]
public class SysDeptController : ControllerBase
{
    /// <summary>
    /// 通过部门编号删除系统部门服务
    /// </summary>
    public DeleteSysDeptByDeptIdService deleteSysDeptByDeptIdService { get; set; }
    /// <summary>
    /// 通过部门编号删除系统部门
    /// </summary>
    /// <param name="deptIds">部门编号多个逗号分割（1,2,3...）</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpDelete("{deptIds}")]
    public async Task<ResponseMessageModel> DeleteSysDeptByDeptId(string deptIds, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestDeleteSysDeptByDeptIdModel();

        model.DeptIds = deptIds;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => deleteSysDeptByDeptIdService.Execute(model));
    }

    /// <summary>
    /// 添加系统部门服务
    /// </summary>
    public InsertSysDeptService insertSysDeptService { get; set; }
    /// <summary>
    /// 添加系统部门
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPost]
    public async Task<ResponseMessageModel> InsertSysDept([FromBody] RequestInsertSysDeptModel model)
    {
        return await Task.Run(() => insertSysDeptService.Execute(model));
    }

    /// <summary>
    /// 通过部门编号更新系统部门服务
    /// </summary>
    public UpdateSysDeptByDeptIdService updateSysDeptByDeptIdService { get; set; }
    /// <summary>
    /// 通过部门编号更新系统部门
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPut]
    public async Task<ResponseMessageModel> UpdateSysDeptByDeptId([FromBody] RequestUpdateSysDeptByDeptIdModel model)
    {
        return await Task.Run(() => updateSysDeptByDeptIdService.Execute(model));
    }

    /// <summary>
    /// 通过部门编号获取系统部门服务
    /// </summary>
    public GetSysDeptByDeptIdService getSysDeptByDeptIdService { get; set; }
    /// <summary>
    /// 通过部门编号获取系统部门
    /// </summary>
    /// <param name="deptId">部门编号</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{deptId}")]
    public async Task<ResponseMessageModel> GetSysDeptByDeptId(long deptId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetSysDeptByDeptIdModel();

        model.DeptId = deptId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getSysDeptByDeptIdService.Execute(model));
    }

    /// <summary>
    /// 获取系统部门列表服务
    /// </summary>
    public GetSysDeptListService getSysDeptListService { get; set; }
    /// <summary>
    /// 获取系统部门列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("list"), HttpPost]
    public async Task<ResponseMessageModel> GetSysDeptList([FromBody] RequestGetSysDeptListModel model)
    {
        return await Task.Run(() => getSysDeptListService.Execute(model));
    }

    /// <summary>
    /// 分页获取系统部门列表服务
    /// </summary>
    public GetSysDeptPageListService getSysDeptPageListService { get; set; }
    /// <summary>
    /// 分页获取系统部门列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("listPage"), HttpPost]
    public async Task<ResponseMessageModel> GetSysDeptPageList([FromBody] RequestGetSysDeptPageListModel model)
    {
        return await Task.Run(() => getSysDeptPageListService.Execute(model));
    }

    /// <summary>
    /// 获取系统部门树列表服务
    /// </summary>
    public GetSysDeptTreeListService getSysDeptTreeListService { get; set; }
    /// <summary>
    /// 获取系统部门树列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("treeList"), HttpPost]
    public async Task<ResponseMessageModel> GetSysDeptTreeList([FromBody] RequestGetSysDeptListModel model)
    {
        return await Task.Run(() => getSysDeptTreeListService.Execute(model));
    }
}
